<template>
	<view>

		<view class="orders-item" v-for="(item, index ) in ordersList" :key="item.id">
			<uni-card class="card">
				<view class="info" @click="clickInfo(item.id,item.shopId,item.orderType)">
					<view class="left">
						<view class="avatar">
							<u--image :src="item.shopAvatar" shape="circle" width="100rpx" height="100rpx"></u--image>
						</view>
						<view class="more">
							<view class="name">
								{{item.shopName}}

								<view class="u-demo-block" style="margin-left: 10rpx;">
									<view class="u-demo-block__content">
										<view class="u-page__tag-item">
											<u-tag size="mini" :text="item.orderType" v-if="item.orderType == '本片约拍'">
											</u-tag>
											<u-tag size="mini" :text="item.orderType" type="success" v-else>
											</u-tag>
										</view>

									</view>
								</view>

							</view>
							<view class="style">
								{{item.orderStyle}}
							</view>
							<view class="time">
								{{formatOrderTime(item.ordersTime)}}
							</view>
						</view>
					</view>
					<view class="right">
						<view class="orderStatus"
							:class="item.orderStatus == 1 ? 'green':item.orderStatus==2?'yellow':item.orderStatus==4?'red':''">
							{{item.orderStatus == 1 ? '交易成功':item.orderStatus==2?'交易中':item.orderStatus==4?'退款成功':''}}
						</view>
						<view class="orderPrice" style="margin-top: 20rpx;">
							￥{{item.orderPrice}}
						</view>

					</view>
				</view>
				<view class="btn">
					<view class="successfulTransaction_btn" v-if="item.orderStatus == 1">
						<!-- TODO:交易成功按钮 -->
						<view class="" style="width: 100%;" @click="addEvaluate(item.commodityId)">
							<u-button size="mini" type="primary" shape="square" text="追加评价"></u-button>
						</view>
					</view>
					<view class="inTransaction_btn" v-else-if="item.orderStatus == 2">
						<!-- TODO:交易中按钮 -->
						<view @click="cancelOrder(item.id, index)">
							<u-button size="mini" color="#616af3" shape="square" text="取消订单"></u-button>
						</view>
						<view @click="modifyOrder(item.id, item.orderType)">
							<u-button size="mini" type="warning " shape="square" text="修改订单"></u-button>
						</view>
						<view @click="continuePayment(item.id, item.orderType)">
							<u-button size="mini" type="primary" shape="square" text="继续付款"></u-button>
						</view>
					</view>
					<view class="transactionCancellation_btn" v-else-if="item.orderStatus == 3">
						<!-- TODO:交易失败按钮 -->
						<view class="" @click="reorder(item.commodityId, item.shopId, item.orderType, item)">
							<u-button size="mini" color="#616af3" type="primary" shape="square" text="重新下单"></u-button>
						</view>
					</view>
					<!-- 退款订单操作按钮 -->
					<view class="inTransaction_btn" v-else-if="item.orderStatus == 4">
						<view @click="deleteOrder(item.id, index)">
							<u-button size="mini" color="#000" shape="square" text="删除"></u-button>
						</view>
						<view @click="goKeFu()">
							<u-button size="mini" type="primary " shape="square" text="联系客服"></u-button>
						</view>
						<view @click="goShop(item.shopId)">
							<u-button size="mini" type="primary" shape="square" text="联系卖家"></u-button>
						</view>
						<view @click="goDetail(item.id)">
							<u-button size="mini" type="primary" shape="square" text="查看详情"></u-button>
						</view>
					</view>
					<!-- <view class="complain_btn" @click="goReasonComplain(item.id)">
							<u-button size="mini" type="primary" shape="circle" text="申请投诉"></u-button>
						</view> -->
				</view>
			</uni-card>
		</view>
	</view>
	</view>
</template>

<script>
	import {
		formatTime
	} from '../../utils/formatTime.js'
	export default {
		data() {
			return {
				ordersList: [{
					// 订单id
					id: '11552336',
					// 商家名称
					shopName: '小黄约拍',
					// 交易状态 1 为交易成功 2 为交易中 3为交易取消  4为退款
					orderStatus: 4,
					// 交易时间
					ordersTime: 1692786334,
					// 商家头像
					shopAvatar: 'https://cdn.uviewui.com/uview/album/1.jpg',
					// 订单价格
					orderPrice: '888.00',
					// 商品数量
					count: '1',
					// 类型
					orderType: '本片约拍',
					// 风格
					orderStyle: '写真/古风/古代千金园林风',
					// 商品id
					commodityId: '115523',
					// 商家id
					shopId: '11235'
				}, {
					// 订单id
					id: '11599836',
					// 商家名称
					shopName: '小黄约拍',
					// 交易状态
					orderStatus: 4,
					// 交易时间
					ordersTime: 2692750334,
					// 商家头像
					shopAvatar: 'https://cdn.uviewui.com/uview/album/2.jpg',
					// 订单价格
					orderPrice: '888.00',
					// 商品数量
					count: '1',
					// 类型
					orderType: '自主约拍',
					// 风格
					orderStyle: '写真',
					// 商品id
					commodityId: '115523',
					// 商家id
					shopId: '11235'

				}, {
					// 订单id
					id: '11693236',
					// 商家名称
					shopName: '小黄约拍',
					// 交易状态
					orderStatus: 4,
					// 交易时间
					ordersTime: 1992764734,
					// 商家头像
					shopAvatar: 'https://cdn.uviewui.com/uview/album/3.jpg',
					// 订单价格
					orderPrice: '888.00',
					// 商品数量
					count: '1',
					// 类型
					orderType: '本片约拍',
					// 风格
					orderStyle: '写真',
					// 商品id
					commodityId: '115523',
					// 商家id
					shopId: '11235'

				}, {
					// 订单id
					id: '155296586',
					// 商家名称
					shopName: '小黄约拍',
					// 交易状态
					orderStatus: 4,
					// 交易时间
					ordersTime: 1692764734,
					// 商家头像
					shopAvatar: 'https://cdn.uviewui.com/uview/album/4.jpg',
					// 订单价格
					orderPrice: '888.00',
					// 商品数量
					count: '1',
					// 类型
					orderType: '本片约拍',
					// 风格
					orderStyle: '写真',
					// 商品id
					commodityId: '1154523',
					// 商家id
					shopId: '11235'

				}, {
					// 订单id
					id: '11529966',
					// 商家名称
					shopName: '小黄约拍',
					// 交易状态
					orderStatus: 4,
					// 交易时间
					ordersTime: 1692764734,
					// 商家头像
					shopAvatar: 'https://cdn.uviewui.com/uview/album/5.jpg',
					// 订单价格
					orderPrice: '888.00',
					// 商品数量
					count: '1',
					// 类型
					orderType: '自主约拍',
					// 风格
					orderStyle: '写真',
					// 商品id
					commodityId: '115523',
					// 商家id
					shopId: '11235'

				}],
			};
		},
		methods: {
			// 点击信息跳转
			clickInfo(workId, shopId, orderType) {
				if (orderType == '本片约拍') {
					uni.navigateTo({
						url: `/PackageB/photoDetail/photoDetail?id=${workId}`
					})
				} else {
					uni.navigateTo({
						url: `/subPackages_pipei/shop/shop?id=${shopId}`
					})
				}
			},
			// 删除订单
			deleteOrder(id, index) {
				uni.showModal({
					title: '删除订单',
					content: '是否删除该订单',
					success: (res) => {
						if (res.confirm) {
							this.ordersList.splice(index, 1)
							// 删除后提示
							uni.showToast({
								title: '删除订单成功！'
							})
							console.log('用户点击确定');
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				})

			},
			// 联系客服按钮
			goKeFu() {
				uni.navigateTo({
					url: `/PackageB/KeFu/KeFu`
				})
			},
			// 联系卖家
			goShop(shopId) {
				uni.navigateTo({
					url: `/pages/message/messageroom/messageroom?id=${shopId}`
				})
			},
			// 查看退款详情
			goDetail(id) {
				uni.navigateTo({
					url: `/subPackages_user/AfterSalesDetail/AfterSalesDetail?id=${id}`
				})
			},
			// 订单时间格式化
			formatOrderTime(time) {

				return formatTime(time, 8)
			}
		},
	}
</script>

<style lang="scss">
	.card {

		.info {
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin-bottom: 30rpx;
			border-bottom: 1px solid #f8f8f8;

			.left {
				display: flex;
				justify-content: space-between;
				align-items: center;

				.avatar {
					margin-right: 20rpx;
				}

				.more {
					.name {
						display: flex;
						align-items: center;
						font-size: $uni-font-size-lg;
						font-weight: 900;
						margin-bottom: 10rpx;
					}
				}
			}

			.right {
				margin-left: 10rpx;

				.orderStatus {
					margin-bottom: 10rpx;

				}

				.count {
					display: flex;
					justify-content: flex-end;
				}
			}
		}

		.btn {
			width: 100%;
			display: flex;
			justify-content: flex-end;
			align-items: center;

			.successfulTransaction_btn {
				width: 150rpx;
				display: flex;
				flex-direction: row;
				justify-content: flex-end;
			}

			.inTransaction_btn {
				display: flex;
				justify-content: space-between;

				view {
					width: 130rpx;
					margin-left: 30rpx;
				}
			}

			.transactionCancellation_btn {
				width: 150rpx;
				display: flex;
				justify-content: flex-end;
			}
		}

	}

	.red {
		color: #e10000;
	}
</style>